package com.example.tccdemo.config;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @describte:TODO
 * @program:distribute-transaction
 * @author:zhengdp
 * @create:2021-09-27 19:34:21
 **/
@Configuration
public class ZkConfig {

    @Bean(initMethod = "start",destroyMethod = "close")
    public CuratorFramework getCuratorFramework(){
        String zookeeperConnectionString = "192.168.0.131:2181";
        // 重试策略
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
        CuratorFramework client = CuratorFrameworkFactory.newClient(zookeeperConnectionString,
                retryPolicy);
        return client;
    }
}
